<?php

require_once "scripts/config.php";

function buildHead($title, $cssArray = array()){
    global $sessLoggedIn;
    global $sessFirstTime;
    global $config;
    global $sessionError;
    
    ?>
    <!DOCTYPE html>
    <html>
    <head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<meta name="Googlebot"          content="index,follow" />
	<meta name="Robots"             content="index,follow" />
	<meta name="author"             content="Ryan J. Sullivan" />
	<meta name="copyright"          content="&copy; 2011 Ryan Sullivan" />
	<title>
	    Mineshafter Squared <?php echo ":: ". $title .";" ?>
	</title>
	<link rel="stylesheet" type="text/css" href="css/sitewide.css" />
	<?php
	foreach($cssArray as $filename){
	    echo '<link rel="stylesheet" type="text/css" href="css/'.$filename.'" />'."\n";
	}
	?>
	<meta name="keywords"     content="Minecraft, Mineshafter, Free Minecraft, Minecraft Server, Mineshafter Squared, Mineshafter 2" />
	<meta name="description"  content="A free and open source alternative to the official Minecraft authentication service" />
	<script type="text/javascript">
	    var _gaq = _gaq || [];
	    _gaq.push(['_setAccount', 'UA-24037493-1']);
	    _gaq.push(['_trackPageview']);
	  
	    (function() {
	      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	    })();
	</script>
    </head>
    <body>
	<div id="pageTop">
	    <div id="topMenu">
		<a href="http://www.mineshaftersquared.com" class="first">Home</a>
		<a href="downloads.php">Downloads</a>
		<a href="faq.php">F.A.Q.</a>
		<a href="http://kayoticgamer.com/forum/viewforum.php?f=1">Forums</a>
	    </div>
	</div>
	<div id="siteWrapper">
	    <div id="headNav">
		<img id="siteLogo" src="images/mineshafterlogo.png" alt="Mineshafter Squared Logo" />
	    </div>
	    <div id="blockArea" class="clear">
		<div class="column first">
		    <div class="block">
			<h2 class="newsimg">
			    Announcements
			</h2>
			<div class="content">
			    Coming Soon!
			</div>
		    </div>
		</div>
		<div class="column">
		    <?php
		    if(!$sessLoggedIn){
			?>
			<div class="block">
			    <h2 class="manimg">
				Log in
			    </h2>
			    <div class="content">
				<div class="infoBox">
				    Use your Minecraft Account to login.
				</div>
				<div class="loginBox">
				    <form action="#" method="POST">
					<input type="hidden" name="loginform" value="true" />
					<div class="formItem first">
					    <label for="username">
						Username
						<span class="required">*</span>
					    </label>
					    <input type="text" name="username" />
					</div>
					<div class="formItem">
					    <label for="password">
						Password
						<span class="required">*</span>
					    </label>
					    <input type="password" name="password" />
					</div>
					<div class="formItem">
					    <input type="submit" value="Login" />
					</div>
				    </form>
				</div>
			    </div>
			</div>
			<?php
		    } else{
			?>
			<div class="block">
			    <h2 class="manimg">
				    <?= $_SESSION['username']; ?>
			    </h2>
			    <div class="content">
				<ul class="menu">
				    <li>
					<input type="hidden" name="logoutform" value="true" />
					<span class="userButton">
					    <a href="skins.php">Upload Skin</a>
					</span>
				    </li>
				    <li>
					<form id="logoutForm" action="#" method="POST">
					    <input type="hidden" name="logoutform" value="true" />
					    <span class="userButton" onclick="$('#logoutForm').submit();">
						Logout
					    </span>
					</form>
				    </li>
				</ul>
			    </div>
			</div>
			<?php
		    }
		    ?>
		</div>
		<div class="column last">
		    <div class="block">
			<h2 class="menuimg">
			    Server Statistics
			</h2>
			<div class="content">
			    Coming Soon!
			</div>
		    </div>
		</div>
	    </div>
	    <div id="slideShadow">
		<div id="messageCenter">
		</div>
	    </div>
	
    <?php
}

function buildFoot($jsArray = array()){
    global $sessLoggedIn;
    global $sessFirstTime;
    global $config;
    global $sessionError;
    
    ?>
	</div>
	<div id="pageBottom">
	    <div id="pageBottomInside">
		<p>
		    &copy; 2011 Copyright Ryan Sullivan, Kayotic Labs. All Rights Reserved.
		    Theme based off of <a href="http://drupal.org/project/bluemasters">BlueMaster's Drupal Theme</a>
		</p>
	    </div>
	</div>
    </body>
    </html>
    <?php
    foreach($jsArray as $filename){
	echo '<script type="text/javascript" src="'.$filename.'"></script>'."\n";
    }
    
    ?>
    <script type="text/javascript">
    $(document).ready(function(){
    <?php
    
    if($sessLoggedIn){
	if($sessFirstTime){
	    echo 'MessageCenter.addMessage("'.$config['message']['firstLogin'].'");'."\n";
	}
    } else if($sessionError){
	echo 'MessageCenter.addMessage("'.$sessionError.'", "#FF0000");'."\n";
    }
    ?>
    });
    </script>
    <?php
}

?>